package com.example.wallpaperapp.utils;

import android.app.Activity;
import android.os.Build;
import android.view.Window;
import android.view.WindowManager;

/**
 * 状态栏工具类
 */
public class StatusBar {
    //状态栏的修改必须写在setContentView前面
    //设置沉浸状态栏
    public static void SetStatusBar(Window window){
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        // 透明状态栏
        window.addFlags(
                WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);

    }
}
    //是否显示状态栏 否的话调用
    public static void ShowStatusBar(Window window){
        window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN
                , WindowManager.LayoutParams.FLAG_FULLSCREEN);
    }
    //获取状态栏高度
    public static int getStatusBarHeight(Activity activity) {
        int result = 0; //获取状态栏高度的资源id
        int resourceId = activity.getResources().getIdentifier("status_bar_height", "dimen", "android");
        if (resourceId > 0) {
            result =activity.getResources().getDimensionPixelSize(resourceId);
        }
        return result;
    }
}
